import numpy as np
from scipy.interpolate import UnivariateSpline
import os
import csv
import pandas as pd
# 需注意2020年为闰年，所以不是闰年的时候将8784改为8760
x = np.arange(0, 8784)[np.arange(0, 8784) % 3 == 0]
xnew = np.arange(0, 8784)[np.arange(0, 8784) % 3 != 0]
in_folder_path = "D:\\能经\\ssp245_20"
out_folder_path = "D:\\能经\\ssp245_2020_cha"
i = 0
for file in os.listdir(in_folder_path):
    results = []
    filePath = os.path.join(in_folder_path, file)
    df = pd.read_csv(filePath, encoding='gbk')
    y = list(df.iloc[:, 1])
    fun = UnivariateSpline(x, y, s=0)
    y1 = fun(xnew)
    j = 0
    m = 0
    for i in range(8784):
        if i%3 == 0:
            results.append(y[j])
            j += 1
            print(j)
        else:
            results.append(y1[m])
            m += 1
    out_file = os.path.join(out_folder_path, file)
    out_file = out_file + ".csv"
    x3 = np.arange(1, 8785)
    data = {'time': x3,
            'sfcWind': results
            }
    df1 = pd.DataFrame(data)
    df1.to_csv(out_file, index=False)
    print("成功！")